package com.yesorno.activity;

import java.util.Timer;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import com.yesorno.constants.Constants;
import com.yesorno.model.MyTimerTask;

/**
 * 用户消息提醒的service
 * 
 * @author samoin
 * @version v0.1
 * @since 2011-08-19
 * 
 */
public class AlertService extends Service {

	// 定义个一个Tag标签
	private static final String TAG = "YesOrNoService";
	// 这里定义吧一个Binder类，用在onBind()有方法里，这样Activity那边可以获取到
	private MyBinder mBinder = new MyBinder();

	public static Timer timer;

	@Override
	public void onCreate() {
		super.onCreate();
		linsterMessage();
	}

	@Override
	public IBinder onBind(Intent intent) {
		Log.d(TAG, "start IBinder~~~");
		return mBinder;
	}

	private void linsterMessage() {
		if (timer == null) {
			timer = new Timer(true);
			MyTimerTask myTimerTask = MyTimerTask
					.getInstance(AlertService.this);
			timer.schedule(myTimerTask, 1000, Constants.COMMON_SLEEP_TIME);
		}
	}

	public class MyBinder extends Binder {
		public AlertService getService() {
			return AlertService.this;
		}
	}
}
